home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2002 #3 / Amiga Plus CD - 2002 - No. 03.iso / AmigaPlus / Tools / Development / envCPP31 / c++ / samples / empty-shell / main.c next >
Encoding:
C/C++ Source or Header  |  2002-01-01  |  6.0 KB  |  297 lines

  1. /* -----------------------------------------------------------------------------
  2.  
  3.   <INSERT PROJECT DESCRIPTION HERE AND DELETE THIS LINE>
  4.  
  5. */
  6.  
  7. /* /// "includes" */
  8.  
  9. /* include typical set of standard headers */
  10.  
  11. #include <stdio.h>
  12. #include <stdlib.h>
  13. #include <string.h>
  14. #include <ctype.h>
  15. #include <stdarg.h>
  16.  
  17. /* include typical set of Amiga headers */
  18.  
  19. #include <exec/exec.h>
  20. #include <dos/dos.h>
  21. #include <dos/dostags.h>
  22. #include <dos/dosextens.h>
  23. #include <dos/datetime.h>
  24. #include <graphics/gfx.h>
  25. #include <graphics/gfxmacros.h>
  26. #include <graphics/layers.h>
  27. #include <intuition/intuition.h>
  28. #include <intuition/intuitionbase.h>
  29. #include <workbench/workbench.h>
  30. #include <workbench/startup.h>
  31. #include <workbench/icon.h>
  32. #include <datatypes/pictureclass.h>
  33. #include <libraries/asl.h>
  34. #include <libraries/commodities.h>
  35. #include <libraries/gadtools.h>
  36. #include <libraries/iffparse.h>
  37. #include <libraries/locale.h>
  38. #include <rexx/rxslib.h>
  39. #include <rexx/storage.h>
  40. #include <rexx/errors.h>
  41. #include <utility/hooks.h>
  42.  
  43. /* include prototypes (#define INCLUDE_PRAGMAS to include pragmas to use registered arguments) */
  44.  
  45. #ifdef INCLUDE_PRAGMAS
  46.  
  47.     #include <proto/asl.h>
  48.     #include <proto/commodities.h>
  49.     #include <proto/datatypes.h>
  50.     #include <proto/diskfont.h>
  51.     #include <proto/dos.h>
  52.     #include <proto/exec.h>
  53.     #include <proto/gadtools.h>
  54.     #include <proto/graphics.h>
  55.     #include <proto/icon.h>
  56.     #include <proto/iffparse.h>
  57.     #include <proto/intuition.h>
  58.     #include <proto/layers.h>
  59.     #include <proto/locale.h>
  60.     #include <proto/rexxsyslib.h>
  61.     #include <proto/utility.h>
  62.     #include <proto/wb.h>
  63.  
  64. #else
  65.  
  66.     #include <clib/asl_protos.h>
  67.     #include <clib/commodities_protos.h>
  68.     #include <clib/datatypes_protos.h>
  69.     #include <clib/diskfont_protos.h>
  70.     #include <clib/dos_protos.h>
  71.     #include <clib/exec_protos.h>
  72.     #include <clib/gadtools_protos.h>
  73.     #include <clib/graphics_protos.h>
  74.     #include <clib/icon_protos.h>
  75.     #include <clib/iffparse_protos.h>
  76.     #include <clib/intuition_protos.h>
  77.     #include <clib/layers_protos.h>
  78.     #include <clib/locale_protos.h>
  79.     #include <clib/rexxsyslib_protos.h>
  80.     #include <clib/utility_protos.h>
  81.     #include <clib/wb_protos.h>
  82.  
  83. #endif
  84.  
  85. /* /// */
  86. /* /// "prototypes" */
  87.  
  88. extern int            main   (int argc, char **argv);
  89. extern int            wbmain (struct WBStartup *wbs);
  90. extern struct Config *Init   (void);
  91. extern int            Main   (struct Config *config);
  92. extern void           CleanUp(struct Config *config);
  93.  
  94. /* /// */
  95. /* /// "definitions" */
  96.  
  97. /* EDIT PROGRAM NAME AND VERSION AND DELETE THIS LINE */
  98.  
  99. #define PROGRAMNAME     "unnamed"
  100. #define VERSION         "1.0"
  101.  
  102. /* change #define to #undef to disable start via workbench */
  103.  
  104. #define GENERATEWBMAIN
  105.  
  106. /* define command syntax and number of options */
  107.  
  108. #define RDARGS_TEMPLATE ""
  109. #define RDARGS_OPTIONS  0
  110.  
  111. /* define amiga-style version tag */
  112.  
  113. #if defined(__SASC)
  114.     const UBYTE VersionTag[] = "$VER: " PROGRAMNAME " " VERSION " "  __AMIGADATE__ "\n\0";
  115. #elif defined(_DCC)
  116.     const UBYTE VersionTag[] = "$VER: " PROGRAMNAME " " VERSION " (" __COMMODORE_DATE__ ")\n\0";
  117. #else
  118.     const UBYTE VersionTag[] = "$VER: " PROGRAMNAME " " VERSION " (" __DATE__ ")\n\0";
  119. #endif
  120.  
  121. /* /// */
  122. /* /// "struct" */
  123.  
  124. /* ---------------------------------- Config -----------------------------------
  125.  
  126.  Global data
  127.  
  128. */
  129.  
  130. struct Config
  131. {
  132.     struct RDArgs *RDArgs;
  133.  
  134.     #if RDARGS_OPTIONS
  135.  
  136.         LONG Options[RDARGS_OPTIONS];
  137.  
  138.     #endif
  139.  
  140.     /* <INSERT YOUR GLOBAL DATA HERE AND DELETE THIS LINE> */
  141. };
  142.  
  143. /* /// */
  144. /* /// "entry points" */
  145.  
  146. /* ----------------------------------- main ------------------------------------
  147.  
  148.  Shell/wb entry point
  149.  
  150. */
  151.  
  152. int
  153. main(int argc, char **argv)
  154. {
  155.     struct Config *config;
  156.  
  157.     if (argc == 0)
  158.     {
  159.         wbmain((struct WBStartup *)argv);
  160.     }
  161.     else if (config = Init())
  162.     {
  163.         #if RDARGS_OPTIONS
  164.  
  165.             /* parse startup options */
  166.  
  167.             int result;
  168.  
  169.             if (config->RDArgs = ReadArgs(RDARGS_TEMPLATE, config->Options, NULL))
  170.             {
  171.                 result = Main(config);
  172.             }
  173.             else
  174.             {
  175.                 PrintFault(IoErr(), PROGRAMNAME);
  176.  
  177.                 result = 20;
  178.             }
  179.  
  180.         #else
  181.  
  182.             int result = Main(config);
  183.  
  184.         #endif
  185.  
  186.         CleanUp(config);
  187.  
  188.         return(result);
  189.     }
  190.     else
  191.         return(20);
  192. }                                       
  193.  
  194. /* ---------------------------------- wbmain -----------------------------------
  195.  
  196.  Workbench entry point
  197.  
  198. */
  199.  
  200. int
  201. wbmain(struct WBStartup *wbs)
  202. {
  203.     #ifdef GENERATEWBMAIN
  204.  
  205.         struct Config *config;
  206.  
  207.         if (config = Init())
  208.         {
  209.             int result = Main(config);
  210.  
  211.             CleanUp(config);
  212.  
  213.             return(result);
  214.         }
  215.         else
  216.             return(20);
  217.  
  218.     #else
  219.  
  220.         return(20);
  221.  
  222.     #endif
  223. }
  224.  
  225. /* /// */
  226. /* /// "initialize" */
  227.  
  228. /* ----------------------------------- Init ------------------------------------
  229.  
  230.  Initialize program. Allocate a config structure to store configuration data.
  231.  
  232. */
  233.  
  234. struct Config *
  235. Init()
  236. {
  237.     struct Config *config;
  238.  
  239.     if (config = (struct Config *)malloc(sizeof(struct Config)))
  240.     {
  241.         memset(config, 0, sizeof(struct Config));
  242.  
  243.         /* <INSERT YOUR INITIALIZATION CODE HERE AND DELETE THIS LINE> */
  244.     }
  245.  
  246.     return(config);
  247. }
  248.  
  249. /* /// */
  250. /* /// "main" */
  251.  
  252. /* ----------------------------------- Main ------------------------------------
  253.  
  254.  Main program. Result: 0 (ok), 5 (warning), 20 (fatal error)
  255.  
  256. */
  257.  
  258. int
  259. Main(struct Config *config)
  260. {
  261.     /* <INSERT YOUR MAIN PROGRAM CODE HERE AND DELETE THIS LINE> */
  262.  
  263.     ;
  264.  
  265.     return(0);
  266. }
  267.  
  268. /* /// */
  269. /* /// "cleanup" */
  270.  
  271.  
  272. /* ---------------------------------- CleanUp ----------------------------------
  273.  
  274.  Free allocated resources
  275.  
  276. */
  277.  
  278. void
  279. CleanUp(struct Config *config)
  280. {
  281.     if (config)
  282.     {
  283.         /* <INSERT YOUR CLEAN-UP CODE HERE AND DELETE THIS LINE> */
  284.  
  285.         #if RDARGS_OPTIONS
  286.  
  287.             if (config->RDArgs)
  288.  
  289.                 FreeArgs(config->RDArgs);
  290.         #endif
  291.  
  292.         free(config);
  293.     }
  294. }
  295.  
  296. /* /// */
  297.